package com.cat.dataStructure03;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.stream.IntStream;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/query-kth-smallest-trimmed-number/
 * @create 2025/11/12 16:11
 * @since JDK17
 */

public class Solution47 {
    public int[] smallestTrimmedNumbers(String[] nums, int[][] queries) {
        int n = nums.length, m = queries.length, k = nums[0].length();
        int[] ans = new int[m];
        String[] temp = new String[n];
        for (int l = 0; l < m; l++) {
            var q = queries[l];
            var idx = new ArrayList<>(Arrays.asList(IntStream.range(0, nums.length).boxed().toArray(Integer[]::new)));
            Collections.sort(idx, Comparator.comparing(i -> nums[i].substring(k - q[1])));
            ans[l] = idx.get(q[0] - 1);
        }

        return ans;
    }
}
